<template>
  <div class="top">
    <div class="content">
      <div class="left" @click="goHome">
        <img src="../../assets/images/logo.png" alt="">
        <p>尚医通 预约挂号统一平台</p>
      </div>
      <div class="right">
        <p class="help">帮助中心</p>
        <p class="login" @click="login" v-if="!userStore.userInfo.name">登录/注册</p>
        <el-dropdown v-else>
          <span class="el-dropdown-link">
            {{ userStore.userInfo.name }}
            <el-icon class="el-icon--right">
              <arrow-down />
            </el-icon>
          </span>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item @click="goUser('/user/certification')">实名认证</el-dropdown-item>
              <el-dropdown-item @click="goUser('/user/order')">挂号订单</el-dropdown-item>
              <el-dropdown-item @click="goUser('user/patient')">就诊人管理</el-dropdown-item>
              <el-dropdown-item @click="logout">退出登录</el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </div>
    </div>
  </div>
</template>

<script setup lang=ts>
import { ArrowDown } from '@element-plus/icons-vue'
//引入路由器
import { useRouter } from 'vue-router';
//引入仓库:其中的visible可以控制Login组件对话框的显示和隐藏
//@ts-ignore
import useUserStore from '@/store/modules/user';

//用户仓库
let userStore = useUserStore()
//路由器
let $router = useRouter()

//点击回到首页的回调
const goHome = () => {
  $router.push({
    path: '/home'
  })
}
//控制登陆组件对话框的显示和隐藏
const login = () => {
  userStore.visible = true
}
//点击退出登录按钮的回调
const logout = () => {
  //通知pinia仓库清除用户数据和本地存储数据
  userStore.logout()
  //跳转首页
  goHome()
}
//点击下拉菜单跳转页面的回调
const goUser = (path: string) => {
  $router.push({
    path,
  })
}
</script>

<style scoped lang="scss">
.top {
  position: fixed;
  z-index: 999;
  width: 100%;
  height: 70px;
  background: #fff;
  display: flex;
  justify-content: center;

  .content {
    width: 1200px;
    height: 70px;
    background: white;
    display: flex;
    justify-content: space-between;

    .left {
      display: flex;
      justify-content: center;
      align-items: center;

      img {
        width: 50px;
        height: 50px;
        margin-right: 10px;
      }

      p {
        font-size: 20px;
        color: #55a6fe;
      }
    }

    .right {
      display: flex;
      justify-content: center;
      align-content: center;
      font-size: 14px;
      color: #bbb;

      .help {
        margin-right: 10px;
      }
    }
  }
}
</style>